<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!-- 搜索 -->
      <el-input v-model="query.technicianId" clearable placeholder="输入技师id" style="width: 200px;" class="filter-item"
        @keyup.enter.native="toQuery" />
      <!-- <el-select v-model="query.prizeType" clearable placeholder="奖品分类" class="filter-item" filterable
        style="width: 130px">
        <el-option v-for="item in optionsMetaShow" :disabled="item.disabled === 0" :value="item.id" :key="item.id"
          :label="item.title"></el-option>
      </el-select> -->
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
      <!-- 新增 -->
      <div style="display: inline-block;margin: 0px 2px;">
        <el-button class="filter-item" size="mini" type="primary" icon="el-icon-plus" @click="toAddURL">
          新增项目
        </el-button>
        <el-button type="danger" class="filter-item" size="mini" icon="el-icon-refresh" @click="toQuery">刷新</el-button>
        <el-button type="info" class="filter-item" size="mini" icon="el-icon-close" @click="reset">重置</el-button>
      </div>
    </div>
    <!--表单组件-->
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" size="small" style="width: 100%;">
      <el-table-column prop="id" width="140" label="ID">
      </el-table-column>
      <el-table-column prop="technicianId" width="140" label="技师ID">
      </el-table-column>
      <el-table-column prop="itemName" label="项目名称">
      </el-table-column>
      <el-table-column  label="项目logo图">
        <template slot-scope="scope">
          <img :src="scope.row.itemImg" width="80px" alt="">
        </template>
      </el-table-column>
      <el-table-column prop="originalPrice" label="原价(元)"></el-table-column>
      <el-table-column prop="discountedPrice" label="折扣价(元)">

      </el-table-column>
      <el-table-column label="项目时长(分钟)" align="" prop="itemDate">
      </el-table-column>
      <el-table-column label="状态" align="center">
        <template slot-scope="scope">
          <div>
            <el-tag :type="scope.row.state==1?'warning':scope.row.state==2?'success':'danger'">
            {{ scope.row.state==1?'待审核':scope.row.state==2?'已通过':'已拒绝' }}
            </el-tag>
          </div>
        </template>
      </el-table-column>




      <el-table-column  width="160" label="创建时间">
        <template slot-scope="scope">
          <span>{{ formatTimeTwo(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="265px" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-user-solid"
            :disabled="scope.row.state!=1"
            @click="examine(scope.row)"
           >
          审核
        </el-button>
          <el-button size="mini" type="primary" icon="el-icon-edit" @click="toUpdateURL(scope.row)">
            编辑
          </el-button>
          <el-popover :ref="scope.row.id" placement="top" width="180">
            <p>确定删除本条数据吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
              <el-button :loading="delLoading" type="primary" size="mini"
                @click="subDelete(scope.row.id)">确定</el-button>
            </div>
            <el-button slot="reference" type="danger" icon="el-icon-delete" size="mini">删除</el-button>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <eForm ref="form" :is-add="isAdd" />
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="700px"

      >
      <el-form  ref="formValidate"  :model="form" label-width="130px" >
        <el-row :gutter="24">
          <!-- 商家信息-->

          <el-col :span="24">
            <el-form-item label="审核结果:" >
              <el-radio-group v-model="form.state">
                <el-radio :label="2">通过</el-radio>
                <el-radio :label="3">拒绝</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="form.state==3">
            <el-form-item label="审核建议">
              <el-input v-model="form.remark" type="textarea" :rows="3" placeholder="请输入拒绝建议" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="examineResult()">确 定</el-button>
      </span>
    </el-dialog>
    <!--分页组件-->
    <el-pagination :total="total" :current-page="page + 1" style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes" @size-change="sizeChange" @current-change="pageChange" />

  </div>
</template>

<script>
import initData from '@/mixins/crud'
import { delItem,examineItem } from '@/api/technician'
import eForm from './form3'
import { formatTimeTwo } from '@/utils/index'

import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import Treeselect from '@riophae/vue-treeselect'
export default {
  components: { Treeselect, eForm },
  mixins: [initData],
  data() {
    return {
      dropDownValue: '',
      optionsMetaShow: [
        {
          title: "实物", id: 1
        },
        {
          title: "优惠卷", id: 2
        },
        {
          title: "微信返现", id: 3
        },
      ],
      form:{
        state:2,
        remark:''
      },
      id:0,
      delLoading: false,
      dialogVisible: false,
      query: {
        prizeName: '',
        prizeType: ''
      },
      isAttr: false,
    }
  },
  created() {
    this.$nextTick(() => {
      if (this.$route.params.id) {
        this.query.technicianId=this.$route.params.id
        this.$refs.form.options=[{
          technicianName:this.$route.params.technicianName,
          uid:this.$route.params.id
        }]
        this.$refs.form.technicianId=this.$route.params.id

      }
      this.init().then(() => {

      })
    })
  },
  methods: {
    formatTimeTwo,
    reset() {
      this.query.prizeName = ''
      this.query.prizeType = ''
      this.toQuery()
    },
    examineResult(){
      examineItem({
        ...this.form,
        id:this.id
      }).then(res=>{
      this.dialogVisible=false
      this.init()


      })
    },

    examine(data){
      console.log(data)
      this.dialogVisible=true
      this.id=data.id
    },
    toAddURL() {
      this.isAdd = true
      this.$refs.form.dialog = true
    },
    toUpdateURL(row) {
      this.isAdd = false
      this.$refs.form.dialog = true

      this.$refs.form.form = {
        id: row.id,
        discountedPrice:row.discountedPrice,//	折扣价
        itemDate:row.itemDate,//	项目服务时长
        itemImg:row.itemImg,//	项目logo图
        itemName:row.itemName,	//项目名称
        originalPrice:row.originalPrice,//原价
        // state:1,
        technicianId:row.technicianId,//技师ID
      }
      console.log(this.$refs.form.form)
    },

    beforeInit() {

      this.url = 'api/yxTechnicianItem'
      const sort = 'id,desc'
      this.params = { page: this.page, size: this.size, sort: sort }
      return true
    },
    subDelete(id) {
      console.log(id)
      this.delLoading = true
      let data = [id]

      delItem(data).then(res => {
        this.delLoading = false
        this.$refs[id].doClose()
        this.dleChangePage()
        this.init()
        this.$notify({
          title: '删除成功',
          type: 'success',
          duration: 2500
        })
      }).catch(err => {
        this.delLoading = false
        this.$refs[id].doClose()
        console.log(err.response.data.message)
      })
    },
  }
}
</script>

<style scoped></style>
